<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
<div id="app">
    <ul>
        <!-- 不规范的写法 -->
        <!-- <li v-for="item in arr" :key="item.title" v-if="item.flag">{{item.title}}</li> -->
        <li v-for="item in newArr" :key="item.title">{{item.title}}</li>
    </ul>
</div>
</body>

</html>
<script src='https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js'></script>
<script>
    //只渲染falg为true的数据
    //在vue2中,永远不要把v-for和v-if放到同一个元素上
    //v-for的优先级要比v-if高,原因是底层代码在判断的时候,先判断的是el.for这个逻辑
    //要完成上述需求可以使用computed的写法


    //vue3中的优先级,v-if的优先级比v-for的优先级要高

    let vm = new Vue({
        el: "#app",
        computed: {
            newArr() {
                return this.arr.filter(item => item.flag === true)
            }
        },
        data: {
            arr: [
                {
                    flag: true,
                    title: 'ps5 '
                },
                {
                    flag: false,
                    title: 'switch'
                },
                {
                    flag: true,
                    title: "psp"
                }
            ]
        }
    })
</script>